package com.jeesite.modules.kj.utils;

import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.kj.entity.KjContributeProject;
import com.jeesite.modules.kj.entity.KjMember;
import com.jeesite.modules.kj.entity.KjProjectTeam;
import com.jeesite.modules.kj.entity.KjTeamMember;
import com.jeesite.modules.kj.service.*;

import java.util.List;

public class TeamUtil {
    /**
     * 静态内部类，延迟加载，懒汉式，线程安全的单例模式
     */
    private static final class Static {
        private static KjMemberService kjMemberService = SpringUtils.getBean(KjMemberService.class);
        private static KjProjectTeamService kjProjectTeamService = SpringUtils.getBean(KjProjectTeamService.class);
        private static KjTeamMemberService kjTeamMemberService = SpringUtils.getBean(KjTeamMemberService.class);
    }



    public static String getMemberTeamId(KjMember kjMember, String projectId){
        KjProjectTeam ptWhere = new KjProjectTeam();
        ptWhere.setKjMember(kjMember);
        KjContributeProject cp = new KjContributeProject();
        cp.setId(projectId);
        ptWhere.setKjContributeProject(cp);
        List<KjProjectTeam> pts = Static.kjProjectTeamService.findList(ptWhere);
        if(pts.size() > 0){
            return pts.get(0).getId();
        }else{
            KjTeamMember tmWhere = new KjTeamMember();
            tmWhere.setKjMember(kjMember);
            tmWhere.setProjectId(projectId);
            List<KjTeamMember> tms = Static.kjTeamMemberService.findList(tmWhere);
            if(tms.size() > 0){
                return tms.get(0).getTeamId();
            }
        }
        return "";
    }


}
